/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sun.scheduler.util.collections;

import java.util.Comparator;

/**
 * A class that provides some basic operations on a {}b
 * @author mfj
 */
public class DefaultOrder<E extends Comparable<E>> implements Comparator<E>
{
    @Override
    public int compare(E t, E t1)
    {
        return t.compareTo(t1);
    }


    public <T extends E> T max(T t1, T t2)
    {
        return t1.compareTo(t2) < 0 ? t2 : t1;
    }


    public <T extends E> T max(T t, T... elements)
    {
        T currMax = t;
        for ( T e : elements )
            if ( t.compareTo(e) < 0 )
                currMax = e;
        
        return currMax;
    }

    public <T extends E> T min(T t1, T t2)
    {
        return t1.compareTo(t2) > 0 ? t2 : t1;
    }


    public <T extends E> T min(T t, T... elements)
    {
        T currMin = t;
        for ( T e : elements )
            if ( t.compareTo(e) > 0 )
                currMin = e;
        
        return currMin;
    }
}
